﻿namespace DesignModeConsole.行为型.访问者模式;

/// <summary>
/// 资源文件  违反开闭原则，增加功能了需要修改每个资源类
/// </summary>
public abstract class ResourceFile2
{
    public readonly string _filePath;

    public ResourceFile2(string filePath)
    {
        _filePath = filePath;
    }

    /// <summary>
    /// 提起文本
    /// </summary>
    /// <param name="extractor"></param>
    public abstract void Accept(Extractor extractor);

    /// <summary>
    /// 压缩
    /// </summary>
    /// <param name="compressor"></param>
    public abstract void Accept(CompressorService compressor);
}

public class PptFile2 : ResourceFile2
{
    public PptFile2(string filePath) : base(filePath)
    {
    }

    public override void Accept(Extractor extractor)
    {
        extractor.Extract2txt(this);
    }

    public override void Accept(CompressorService compressor)
    {
        compressor.Compressor(this);
    }
}

public class PdfFile2 : ResourceFile2
{
    public PdfFile2(string filePath) : base(filePath)
    {
    }

    public override void Accept(Extractor extractor)
    {
        extractor.Extract2txt(this);
    }

    public override void Accept(CompressorService compressor)
    {
        compressor.Compressor(this);
    }
}

public class WordFile2 : ResourceFile2
{
    public WordFile2(string filePath) : base(filePath)
    {
    }

    public override void Accept(Extractor extractor)
    {
        extractor.Extract2txt(this);
    }

    public override void Accept(CompressorService compressor)
    {
        compressor.Compressor(this);
    }
}

/// <summary>
/// 提取方法
/// </summary>
public class Extractor
{
    public void Extract2txt(PptFile2 pptFile2)
    {
        Console.WriteLine("提取ppt 地址：" + pptFile2._filePath);
    }

    public void Extract2txt(PdfFile2 pdfFile2)
    {
        Console.WriteLine("提取pdf 地址：" + pdfFile2._filePath);
    }

    public void Extract2txt(WordFile2 wordFile2)
    {
        Console.WriteLine("提取word 地址：" + wordFile2._filePath);
    }
}

/// <summary>
/// 压缩服务
/// </summary>
public class CompressorService
{
    public void Compressor(PptFile2 pptFile2)
    {
        Console.WriteLine("压缩 地址：" + pptFile2._filePath);
    }

    public void Compressor(PdfFile2 pdfFile2)
    {
        Console.WriteLine("压缩 地址：" + pdfFile2._filePath);
    }

    public void Compressor(WordFile2 wordFile2)
    {
        Console.WriteLine("压缩 地址：" + wordFile2._filePath);
    }
}